package cn.rdq.iknessplatform.controller;

import cn.rdq.api.po.Drama;
import cn.rdq.api.po.UserPurse;
import cn.rdq.api.vo.UserPursueVo;
import cn.rdq.common.CommonResult;
import cn.rdq.iknessplatform.service.UserPursueService;
import com.github.pagehelper.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/pursue")
@Api
public class UserPursueController {

    @Autowired
    private UserPursueService userPursueService;

    @PostMapping("/drama")
    @ApiOperation("用户追剧情况")
    public CommonResult getDramaPurse(@RequestBody UserPurse userPurse) {
        UserPurse watched = userPursueService.getWatched(userPurse);
        return CommonResult.successObj(watched);
    }

    @PostMapping("/ing")
    @ApiOperation("我的追剧")
    public CommonResult pagePursuing(@RequestBody UserPursueVo userPursueVo) {
        List<Drama> dramas = userPursueService.userPurseByUserId(userPursueVo);
        return CommonResult.success().pageSuccess(dramas);
    }

    @PostMapping("/watched")
    @ApiOperation("已看完")
    public CommonResult pageWatched(@RequestBody UserPursueVo userPursueVo) {
        PageHelper.startPage(userPursueVo.getCurrentPage(), userPursueVo.getPageSize());
        List<Drama> dramas = userPursueService.userWatchedByUserId(userPursueVo);
        return CommonResult.success().pageSuccess(dramas);
    }

    @PostMapping("")
    public CommonResult purseCommit(@RequestBody UserPurse userPurse) {
        userPursueService.saveOrUpdateWatched(userPurse);
        return CommonResult.success();
    }

    @GetMapping("/cancel/{id}")
    public CommonResult cancelPursue(@PathVariable Long id) {
        userPursueService.removeById(id);
        return CommonResult.success();
    }
}
